import { createRoot } from 'react-dom/client'
import { Spin } from 'antd'

function Loading({ tip = '' }: { tip?: string }) {
  return (
    <Spin tip={tip} size="large" className="request-loading">
      <span style={{ display: 'none' }}>welcome</span>
    </Spin>
  )
}

let count = 0
export const showLoading = () => {
  if (count === 0) {
    const loading = document.createElement('div') as HTMLDivElement
    loading.setAttribute('id', 'global-loading')
    document.body.appendChild(loading)
    createRoot(loading).render(<Loading />)
  }
  count++
}
export const hideLoading = () => {
  count--
  if (count === 0) {
    document.body.removeChild(
      document.getElementById('global-loading') as HTMLDivElement
    )
  }
}
